package com.lcz.databindingdemo;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;

import com.google.gson.Gson;
import com.kymjs.rxvolley.RxVolley;
import com.kymjs.rxvolley.client.HttpCallback;
import com.kymjs.rxvolley.client.HttpParams;
import com.lcz.databindingdemo.databinding.ActivityMainBinding;
import com.lcz.databindingdemo.domain.User;

public class MainActivity extends AppCompatActivity {

    private User user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        user = new User();
        user.name.set("aa");
        user.age.set(16);
        binding.setUser(user);

        new Thread() {
            @Override
            public void run() {
                super.run();
                SystemClock.sleep(2000);
                user.name.set("bb");
                user.age.set(20);
                String url = "http://apis.baidu.com/geekery/music/singer";
                HttpParams params = new HttpParams();
                params.put("name", "陈奕迅");
                params.putHeaders("apikey", "8894f3d9fb5b5af788610513930d7805");

                RxVolley.post(url, params, new HttpCallback() {
                    @Override
                    public void onSuccess(String t) {
                        super.onSuccess(t);
                        Gson gson = new Gson();
                        user.name.set(t);
                    }

                });
            }

        }.start();
    }
}
